/*
 * Copyright 2006 Mark Bakker <mark.bakker AT gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.gwtsvg.client;

/**
 * This class is under consideration for removal, if you have an opion please
 * comment on http://gwtwidgets.blogspot.com.
 */
public class Color {
  public static final Color NONE = new Color("");

  private int r, g, b;

  // only for special cases, like no color, or maybe named colors
  private String colorText = null;

  private Color(String colorText) {
    this.colorText = colorText;
  }

  public Color(int r, int g, int b) {
    this.r = r;
    this.g = g;
    this.b = b;
  }

  public int getBlue() {
    return b;
  }

  public int getGreen() {
    return g;
  }

  public String getHexValue() {
    if (colorText != null) {
      if (colorText.equals("")) {
        return "none";
      }
      return colorText;
    }

    return "#" + pad(Integer.toHexString(r)) + pad(Integer.toHexString(g))
        + pad(Integer.toHexString(b));
  }

  public int getRed() {
    return r;
  }

  public String toString() {
    if (colorText != null) {
      return colorText;
    }
    return "red=" + r + ", green=" + g + ", blue=" + b;
  }

  private String pad(String in) {
    if (in.length() == 0) {
      return "00";
    }
    if (in.length() == 1) {
      return "0" + in;
    }
    return in;
  }

}
